<?php

use App\Kuafu\Activity\Controller\Applet\ActivityController;
use App\Kuafu\Banner\Controller\Applet\BannerController;
use App\Kuafu\Common\Controller\Applet\CommonController;
use App\Kuafu\Common\Controller\Applet\UploadController;
use App\Kuafu\Complain\Controller\Applet\ComplainController;
use App\Kuafu\Config\Controller\Applet\ConfigController as PosConfigController;
use App\Kuafu\CouponPackage\Controller\Applet\CouponPackageController;
use App\Kuafu\Customer\Controller\Applet\CustomerController;
use App\Kuafu\Customer\Controller\Applet\CustomerPlatformController;
use App\Kuafu\Customer\Controller\Applet\LoginController;
use App\Kuafu\CustomerCoupon\Controller\Applet\CustomerCouponController;
use App\Kuafu\Order\Controller\Applet\DyOrderCallbackController;
use App\Kuafu\Order\Controller\Applet\OrderController;
use App\Kuafu\Product\Controller\B\ProductController;
use App\Kuafu\ProductMenu\Controller\Applet\ProductMenuController;
use App\Kuafu\Shop\Controller\Applet\SearchController;
use App\Kuafu\Shop\Controller\Applet\ShopController;
use App\Kuafu\Wechat\Controller\Applet\WechatCallbackController;
use App\Kuafu\Wechat\Controller\Applet\WechatController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API POS Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

//小程序路由

//用户登录
Route::prefix('login')->group(function () {
    Route::post('/', [LoginController::class, 'registerOrLogin']);
});

Route::prefix('index')->group(function () {
    Route::get('getImage', [BannerController::class, 'getAppletIndexImage']);
    Route::get('getAppletPopImage', [BannerController::class, 'getAppletPopImage']);
});

// 菜单
Route::prefix('menu')->group(function () {
    Route::get('shopMenu', [ProductMenuController::class, 'shopMenu']);
});

Route::middleware(['AppletAuth'])->group(function () {
    //用户模块
    Route::prefix('customer')->group(function () {
        Route::post('/', [CustomerController::class, 'addCustomer']);
        Route::get('/', [CustomerPlatformController::class, 'getUserInfo']);
        Route::put('/', [CustomerController::class, 'setCustomer']);
    });
    //订单模块
    Route::prefix('order')->group(function () {
        Route::get('/list', [OrderController::class, 'getUserOrderList']);
        Route::get('/listAll', [OrderController::class, 'getUserOrderListAll']);
        // 获取订单备注列表
        Route::get("/remark", [PosConfigController::class, "getOrderRemark"]);
        Route::get('/{orderId}', [OrderController::class, 'getOrderInfo']);
        Route::post('/pay', [OrderController::class, 'payOrder']);// 订单支付
        Route::post('/unLockPay', [OrderController::class, 'unLockOrderPay']);    // 订单支付解锁
        Route::post("/preCalc", [OrderController::class, "preCalc"]); // 预计价
        Route::post('/', [OrderController::class, "createOrder"])->middleware(['applet.shopStatusOrderAuth']);// 下单
        // 跳转小程序订单详情 - 兼容多种小程序支付
        Route::get('/jumpToMiniOrderDetail/{orderId}', [OrderController::class, 'jumpToMiniOrderDetail'])
             ->withoutMiddleware('AppletAuth');
        //取消订单
        Route::post('/cancel/{orderId}', [OrderController::class, 'cancel']);
    });
    //模板消息
    Route::prefix('subscribe')->group(function () {
        Route::post('/paySend', [WechatController::class, 'payOrderSendMessage']);
        Route::get('/getTemplateList', [WechatController::class, 'getTemplateList']);
    });

    //横幅模块
    Route::prefix('banner')->group(function () {
        Route::get('/bannerList', [BannerController::class, 'getBannerList']);
        Route::get('/bannerRead/{bannerId}', [BannerController::class, 'getBannerById']);
        Route::get('/popList', [ShopController::class, 'popList']);
    });

    // 优惠券包
    Route::prefix('couponPackage')->group(function () {

        // 获取券包信息
        Route::get('/', [CustomerPlatformController::class, 'getCouponDetail']);

        // 购买券包
        Route::post("/buy/{id}", [CouponPackageController::class, "buy"]);
    });

    Route::prefix('shop')->group(function () {
        Route::get('/getUsuallyShop', [ShopController::class, 'getUsuallyShop']);
    });


    //店铺模块
    Route::prefix('shop')->group(function () {
        Route::get('/getRecentlyShop', [ShopController::class, 'getRecentlyShop']);
        Route::get('/getNearShop', [ShopController::class, 'getNearShop'])->middleware('customerThrottle:20,60');
        Route::get('/{shopId}', [ShopController::class, 'getShopInfoByShopId']);
    });


    Route::prefix('common')->group(function () {
        Route::get('/getImageBySceneKey', [CommonController::class, 'getImageBySceneKey']);
    });

});
//公众号订阅
Route::prefix('subscribe')->group(function () {
    Route::get('/callback', [WechatCallbackController::class, 'getCallback']);
    Route::post('/callback', [WechatCallbackController::class, 'postCallback']);
    Route::get('/getQrCode/{shopId}', [WechatCallbackController::class, 'getQrCode']);
    Route::get('/getAccessToken', [WechatCallbackController::class, 'getAccessToken']);
    Route::post('/addCardMaterial', [WechatCallbackController::class, 'addCardMaterial']);
    Route::post('/createMenu', [WechatCallbackController::class, 'createMenu']);//自定义菜单
    Route::get('/getMenu', [WechatCallbackController::class, 'getMenu']);//自定义菜单
});
//菊花码
Route::prefix('order')->group(function () {
    Route::post('/index', [WechatController::class, 'createAppletQrCode']);//小程序首页菊花码
    Route::get('/getQrcode/{orderId}', [OrderController::class, 'createOrderQrCode']);//小程序订单详情菊花码
    Route::get('/qrCodeInfo/{orderToken}', [OrderController::class, 'getOrderDetailByQrCode']);//获取小程序订单详情
});


Route::middleware(['AppletAuth'])->prefix('customerCoupon')->group(function () {
    Route::get("/", [CustomerCouponController::class, "getUserCouponList"]);
    Route::post("/canUseList", [CustomerCouponController::class, "getUserCanUseCouponList"]);
    Route::post("/registerSendCoupon", [CustomerCouponController::class, "bandMobileSendCoupon"]);
    Route::post("/buyCouponPackageSendCoupon", [CustomerCouponController::class, "buyCouponPackageSendCoupon"]);
    Route::get("/detail/{id}", [CustomerCouponController::class, "customerCouponDetail"]);
    Route::get("/checkCouponStatus/{id}", [CustomerCouponController::class, "checkCouponStatus"]);
});

Route::middleware(['AppletAuth'])->prefix('activity')->group(function () {
    // 活动领券
    Route::post("/receiveCoupon/{activityId}", [CustomerCouponController::class, "activityReceiveCoupon"]);
    Route::get("/detail/{id}", [ActivityController::class, "detail"]);

});

// 活动
//Route::middleware(['jwtAuth'])->prefix('activity')->group(function() {
Route::prefix('activity')->group(function () {
    Route::get("/getActivityById/{id}", [ActivityController::class, "getActivityById"]);
    Route::get("/getActivityList", [ActivityController::class, "getActivityList"]);
    Route::post("/", [ActivityController::class, "addActivity"]);
    Route::put("/{id}", [ActivityController::class, "setActivity"]);
    Route::patch("/{id}", [ActivityController::class, "patchActivityStatus"]);
    Route::delete("/{id}", [ActivityController::class, "delActivity"]);
});

//店铺模块
Route::prefix('shop')->group(function () {
    Route::get('/getRecentlyShop', [ShopController::class, 'getRecentlyShop']);
    Route::get('/getNearShop', [ShopController::class, 'getNearShop'])->middleware('customerThrottle:20,60');
    Route::get('/{shopId}', [ShopController::class, 'getShopInfoByShopId']);
    Route::get('/{shopId}/orderStatus', [ShopController::class, 'getShopOrderStatus']);
});

// 文件上传
Route::prefix('upload')->group(function () {
    Route::post('images', [UploadController::class, 'ImagesUpload']);
});

// 投诉建议
Route::prefix('complain')->group(function () {
    Route::post('/', [ComplainController::class, 'add']);
    Route::post('/v2', [ComplainController::class, 'add']);
    Route::get('/issueList', [ComplainController::class, 'issueList']);
});

// 菜品
Route::middleware(['AppletAuth'])->prefix('product')->group(function () {
    Route::get('/{productId}', [ProductController::class, 'detailFromApplet']);//菜品详情

});

// 抖音小程序通知回调
Route::middleware(['DouyinAppletRequest'])->prefix('dyCallback')->group(function () {
    // 抖音回调webhook
    Route::post('/webhook/callback', [DyOrderCallbackController::class, 'challenge']);
    // 抖音小程序订单预下单-扩展点
    Route::post('/order/preOrder', [DyOrderCallbackController::class, 'preOrder']);
    // 抖音小程序订单 退款-扩展点 - 未完成
    Route::post('/order/refund', [DyOrderCallbackController::class, 'demo']);
    // 抖音小程序支付回调 通知
    Route::post('/payment/notify', [DyOrderCallbackController::class, 'paymentNotify']);
    // 抖音小程序退款回调 通知 - 未完成
    Route::post('/refund/notify', [DyOrderCallbackController::class, 'demo']);
    // 抖音小程序优惠券回调 通知
    Route::post('/coupon/notify', [DyOrderCallbackController::class, 'couponVerifyNotify']);
    // 抖音小程序优惠券撤券回调 通知
    Route::post('/coupon/cancelNotify', [DyOrderCallbackController::class, 'demo']);
});

// 夸父点餐小程序搜索
Route::middleware(['AppletAuth'])->prefix('search')->group(function () {
    Route::get('/hot', [SearchController::class, 'hotSearch']);// 热门搜索
    Route::post('/', [SearchController::class, 'addSearch']);// 添加搜索log
});
